// dnSpy decompiler from Assembly-CSharp.dll class: PersistentMusicPlayer
using System;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class PersistentMusicPlayer : CheckedMonoBehaviour
{
	protected override void OnAwake()
	{
		if (this.IsAnotherPersistentPlayerAlive() && !this.IsOtherPlayerPlayingDifferentMusic())
		{
			UnityEngine.Object.Destroy(base.gameObject);
			return;
		}
		if (this.IsAnotherPersistentPlayerAlive() && this.IsOtherPlayerPlayingDifferentMusic())
		{
			PersistentMusicPlayer.DestroyPersistentPlayer();
		}
		PersistentMusicPlayer.instance = this;
		UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		if (MyAudioSettings.IsMusicOn)
		{
			base.GetComponent<AudioSource>().Play();
		}
		else
		{
			PersistentMusicPlayer.Pause();
		}
	}

	private bool IsAnotherPersistentPlayerAlive()
	{
		return PersistentMusicPlayer.instance != null && PersistentMusicPlayer.instance != this;
	}

	private bool IsOtherPlayerPlayingDifferentMusic()
	{
		return base.GetComponent<AudioSource>().clip != PersistentMusicPlayer.instance.GetComponent<AudioSource>().clip;
	}

	public static void DestroyPersistentPlayer()
	{
		if (null != PersistentMusicPlayer.instance)
		{
			UnityEngine.Object.Destroy(PersistentMusicPlayer.instance.gameObject);
			PersistentMusicPlayer.instance = null;
		}
	}

	public static void Pause()
	{
		if (null != PersistentMusicPlayer.instance)
		{
			PersistentMusicPlayer.instance.GetComponent<AudioSource>().Pause();
		}
	}

	public static void Resume()
	{
		if (null != PersistentMusicPlayer.instance)
		{
			PersistentMusicPlayer.instance.GetComponent<AudioSource>().Play();
		}
	}

	private static PersistentMusicPlayer instance;
}
